﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.Objects;


namespace InspectionVehicule.Pages
{
    public partial class Vehicule : PageBase
    {
        private InspectionDAL.Vehicule _donnees;
        public override object State
        {
            get
            {
                return _donnees;
            }
            set
            {
                _donnees = (InspectionDAL.Vehicule)value;
            }
        }           

        protected void Page_Load(object sender, EventArgs e)
        {
            if (Page.IsPostBack)
            {
                _donnees = new InspectionDAL.Vehicule()
                {
                    NoSerie = txtNoSerie.Text,
                    Marque = txtMarque.Text,
                    Modele = txtModele.Text,
                    NoPlaque = txtPlaque.Text,
                    Province = txtProvince.Text,
                    AnneeConstruction = txtAnnee.Text.Length > 0 ? short.Parse(txtAnnee.Text) : (short?)null
                };
                //using (InspectionDAL.InspectionEntities bd = new InspectionDAL.InspectionEntities())
                //{
                //    bd.AddObject("Vehicule", _donnees);
                        
                //    bd.SaveChanges();
                //} 
            }
            else
            {
                if (_donnees != null)
                {
                    txtNoSerie.Text = _donnees.NoSerie;
                    txtMarque.Text = _donnees.Marque;
                    txtModele.Text = _donnees.Modele;
                    txtPlaque.Text = _donnees.NoPlaque;
                    txtProvince.Text = _donnees.Province;
                    txtAnnee.Text = _donnees.AnneeConstruction.ToString();
                }
            }            
        }



        protected override string EtapeEnCours
        {
            get
            {
                return "Vehicule";
            }
            
        }
    }
}